<?php
/**
 * Created by PhpStorm.
 * User: zhengmanbin
 * Date: 2018/9/19
 * Time: 下午5:13
 */

/**
 * get网络请求
 *
 */
function get($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_TIMEOUT, 150);
    $output = curl_exec($ch);
    curl_close($ch);
    $output = iconv("UTF-8", "UTF-8//IGNORE", $output);
    // $output = iconv('GBK','utf-8', $output);
    // $output = htmlspecialchars_decode($output);
    $output = stripslashes(html_entity_decode($output));
    $output1 = preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', trim($output));
    $output1 = str_replace('&quot;', '"', $output1);
    // $output1 = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $output1);
    // $output1 = preg_replace('/[\x{4e00}-\x{9fa5}]/u','title',$output1);
    // echo $output1;
    // echo $output1;
    return $output1;
}

/**
 * post网络请求
 *
 */
function post($url, $post_data = '', $timeout = 5)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    if ($post_data != '') {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_HEADER, false);
    $file_contents = curl_exec($ch);
    curl_close($ch);
    return $file_contents;
}